<template>
  <div class="task-item">
    <div class="tit">
      {{ procedureName }}
    </div>
    <time-select
      v-model="gmtStart"
      title="开始时间"
    />
    <time-select
      v-model="gmtEnd"
      title="结束时间"
    />
  </div>
</template>

<script>
export default {
  name: "TaskItem",
  props: {
    task: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  model: {
    prop: "task",
    event: "change",
  },
  watch: {
    task: {
      handler() {
        this.gmtStart = this.task.gmtStart || '';
        this.gmtEnd = this.task.gmtEnd || '';
      },
      immediate: true,
    },
    gmtStart() {
      let task = this.task;
      task.gmtStart = this.gmtStart;
      this.$emit("change", task);
    },
    gmtEnd() {
      let task = this.task;
      task.gmtEnd = this.gmtEnd;
      this.$emit("change", task);
    },
  },
  computed: {
    procedureName() {
      let procedure = this.preData.procedure.find(item => item.procedureOrder == this.task.procedureOrder)
      return procedure ? procedure.procedureName : '其他'
    }
  },
  data() {
    return {
      gmtStart: "",
      gmtEnd: "",
    };
  },
  created() {
    this.gmtStart = this.task.gmtStart || '';
    this.gmtEnd = this.task.gmtEnd || '';
  },
  methods: {
  }
};
</script>

<style lang="scss" scoped>
.task-item {
  background: #fff;
  margin-bottom: 10px;
  .tit {
    color: #333;
    padding: 10px 15px 0;
    font-weight: 700;
    font-size: 16px;
    line-height: 30px;
    margin: 0 15px;
    position: relative;
    &::before {
      content: "";
      position: absolute;
      display: block;
      height: 20px;
      top: 50%;
      left: 0;
      width: 4px;
      background: #3e88e2;
      border-radius: 2px;
      margin-top: -5px;
    }
  }
}
</style>
